package xjtu.se.articlecommunity.user.myarticle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xjtu.se.articlecommunity.common.CommonService;
import xjtu.se.articlecommunity.common.Result;
import xjtu.se.articlecommunity.common.TokenUtils;
import xjtu.se.articlecommunity.common.dto.CurrentUser;
import xjtu.se.articlecommunity.user.myarticle.impl.MyarticleService;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/user/myarticle")
public class MyarticleAPI {
    @Resource
    MyarticleService service;
    @Resource
    CommonService commonService;

    @GetMapping("/artlist/{u_id}")
    public Result getOwnArtList(@PathVariable String u_id,@RequestHeader("Token") String token,@RequestParam String searchtxt, @RequestParam String ordertype){
        CurrentUser currentUser = TokenUtils.getUserInfo(token,commonService);
        log.info(searchtxt+"    "+ordertype);
        if(u_id.equals(currentUser.getU_id())){
            return Result.success(service.getOwnArt(u_id,searchtxt,ordertype,1));
        }else{
            return Result.success(service.getOwnArt(u_id,searchtxt,ordertype,0));
        }
    }
}
